import { formatDateTime } from './utils'
// 经销商等级变化记录

export default function (sqlite) {
  return {
    // 经销商等级变化记录
    insertDealerLevelChange(dealerId, dealerName) {
      return new Promise((resolve, reject) => {
        const sql =
          'INSERT INTO dealer_level_change(dealer_id,dealer_name,change_date,create_time) VALUES (?, ?, ?, ?)'
        sqlite.run(sql, [dealerId, dealerName, formatDateTime(), formatDateTime()], function (err) {
          if (err) {
            console.error('Error inserting dealer_level_change:', err.message)
            reject(err.message)
          } else {
            resolve(this.lastID)
          }
        })
      })
    },
    // 获取经销商等级变化记录
    getDealerLevelChangeRecord(dealerId) {
      return new Promise((resolve, reject) => {
        const dataSql = `SELECT * FROM dealer_level_change WHERE dealer_id= ? `
        sqlite.all(dataSql, [dealerId], (err, row) => {
          if (err) {
            console.error('Error getDividendPerformanceRecord:', err.message)
            reject(err.message)
          } else {
            resolve(row)
          }
        })
      })
    }
  }
}
